package leetcode.editor.cn;

public class _33_SearchInRotatedSortedArray {
    public static void main(String[] args) {
        Solution solution = new _33_SearchInRotatedSortedArray().new Solution();
        int[] nums = {3, 1};
        int search = solution.search(nums, 1);
        System.out.println(search);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int search(int[] nums, int target) {
            int l = 0, r = nums.length - 1;
            while (l <= r) {
                int mid = l + (r - l) / 2;
                if (target == nums[mid]) {
                    return mid;
                }
                if (nums[mid] >= nums[l])
                    if (target >= nums[l] && target < nums[mid]) {
                        r = mid - 1;
                    } else {
                        l = mid + 1;
                    }
                else {
                    if (target <= nums[r] && target > nums[mid]) {
                        l = mid + 1;
                    } else {
                        r = mid - 1;
                    }
                }
            }
            return -1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}